﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="DeliverGoodsManagement_PrintWindow" Codebehind="PrintWindow.aspx.cs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>无标题页</title>
    <style type="text/css">
    .hide_for_jatools_print {} 
    </style>
    <!-- 插入打印控件 -->
    <object id="jatoolsPrinter" classid="CLSID:B43D3361-D975-4BE2-87FE-FFFF88254255"
        codebase="jatoolsPrinter_f.cab#version=2,1,0,3">
    </object>

    <script type="text/javascript">
    function creatPageDiv(el,id,width,height,bgimg)
    { //创建 PageDIV
       //var o=document.getElementById(el);
       var oDiv = document.createElement("div"); 
       oDiv.style.setAttribute("position","relative");    
       oDiv.style.width=width ;
       oDiv.style.height=height;
  
       //oDiv.style.setAttribute("backgroundImage","url("+bgimg+")"); 
       //创建预揽时背景       
       var oimg=document.createElement("img");
       oimg.setAttribute("position","absolute");
       oimg.setAttribute("src",bgimg);
       oimg.setAttribute("className","hide_for_jatools_print");
       oimg.setAttribute("width",width);
       oimg.setAttribute("height",height);
       oDiv.appendChild(oimg);
       var obj=document.getElementById(id);
       if(obj)
       {
         alert('已经存在该元素');
         return false;
       }
       else
       {
         oDiv.id =id;   
         document.body.appendChild(oDiv);
       }
       
    }
    function creatDiv(el,id,top,left,width,height,text)
    {  //创建DIV元素
       var o=document.getElementById(el);
       var oDiv = document.createElement("div"); 
       oDiv.style.setAttribute("position","absolute");
       oDiv.title="dragable";
       oDiv.style.top=top+"px";
       oDiv.style.left=left+"px";
       oDiv.style.width=width + "px";
       oDiv.style.height=height + "px";        
       oDiv.setAttribute("className","drag");    
       oDiv.style.setAttribute("border","0   solid   #000000");    
       oDiv.style.setAttribute("word-break","break-all");          
       oDiv.innerText=text;
       var obj=document.getElementById(id);
       if(obj)
       {
         alert('已经存在该元素');
         return false;
       }
       else
       {
         oDiv.id =id;   
         document.getElementById(el).appendChild(oDiv)
       }
    }
    
    function CreateOrSubUserDefinedInfoDiv(el,id,top,left,width,height,text)
    {  //创建DIV元素
       var o=document.getElementById(el);
       var oDiv = document.createElement("div"); 
       oDiv.style.setAttribute("position","absolute");
       oDiv.title="dragable";
       oDiv.style.top=top+"px";
       oDiv.style.left=left+"px";
       oDiv.style.width=width + "px";
       oDiv.style.height=height + "px";        
       oDiv.setAttribute("className","drag");    
       oDiv.style.setAttribute("border","0   solid   #000000");    
       oDiv.style.setAttribute("word-break","break-all");          
       oDiv.innerHTML=text;
       var obj=document.getElementById(id);
       if(obj)
       {
         alert('已经存在该元素');
         return false;
       }
       else
       {
         oDiv.id =id;   
         document.getElementById(el).appendChild(oDiv)
       }
    }
    //初始化页面

function Init()
{   

    var url=window.location.href;
    var result = url.split('&');
    
    if(result.length==1)
    {
        
        var tranerId = result[0].split('=');
        
        if(tranerId.length>0)
        {
            
            var str = tranerId[1] + "_";
            DeliverGoodsManagement_PrintWindow.GetData(str,Init_CallBack);  
            doPrint();
        }
    }
    else if(result.length==2)
    {
        
        var tranerId = result[0].split('=');
        var orderId = result[1].split('=');
        if(tranerId.length>0&&orderId.length>0)
        {
            var str = tranerId[1] + "_" + orderId[1];
            
            DeliverGoodsManagement_PrintWindow.GetData(str,Init_CallBack);  
            doPrint();
        }
    }
}
function Init_CallBack(response)
{
     if (response.value != null)
       {                   
        
        var ds = response.value;
        if(ds != null && typeof(ds) == "object" && ds.Tables != null)
        {    
            if(ds.Tables[2]!=null)                
            {
             //alert('aa') ;
                for (var x=0;x<ds.Tables[2].Rows.length;x++)
                {
                    var pageid="page"+(x+1);                   
                    for(var i=0; i<ds.Tables[0].Rows.length; i++)
                    {
                        var width=ds.Tables[0].Rows[i].Img_Width;
                        var height=ds.Tables[0].Rows[i].Img_Heigth;
                        var img=document.getElementById("hidExpressBillImagePath").value + ds.Tables[0].Rows[i].Image;                        
                        creatPageDiv("main",pageid,width,height,img);
                    }
                    if(ds.Tables[1] !=null)
                    {
                        //alert(ds.Tables[1].Rows.length)
                        for(var j=0;j<ds.Tables[1].Rows.length;j++)
                        {
                            var name=ds.Tables[1].Rows[j].STANCE_Name;
                            var top=ds.Tables[1].Rows[j].Top;
                            var left=ds.Tables[1].Rows[j].Left;
                            var width=ds.Tables[1].Rows[j].Width;
                            var height=ds.Tables[1].Rows[j].Heigth;
                            var text=ds.Tables[1].Rows[j].Text;
                            //alert(name);
                            switch (name) 
                            {
                               case "senderName" :
                                    creatDiv(pageid,pageid+"_"+name,top,left,width,height,text);
                                   break;
                               case "senderAddress" :
                                    creatDiv(pageid,pageid+"_"+name,top,left,width,height,text);
                                   break;
                               case "senderCompanyName" :
                                    creatDiv(pageid,pageid+"_"+name,top,left,width,height,text);
                                   break;   
                               case "senderPhone" :
                                    creatDiv(pageid,pageid+"_"+name,top,left,width,height,text);
                                   break;
                               case "senderPostCode" :
                                    creatDiv(pageid,pageid+"_"+name,top,left,width,height,text);
                                   break;
                               case "senderAutograph" :
                                    creatDiv(pageid,pageid+"_"+name,top,left,width,height,text);
                                   break;
                               case "sendDate" :
                                    var dateTime = new   Date().toLocaleString();
                                    var dateTimeArray = dateTime.split(' ');
                                    creatDiv(pageid,pageid+"_"+name,top,left,width,height,dateTimeArray[0]);
                                   break;
                               case "shsj" : 
                                    creatDiv(pageid,pageid+"_",top,left,width,height,text);
                                   break;
                               case "confirm1":
                                    creatDiv(pageid,pageid+"_"+name,top,left,width,height,"√");
                                   break;
                               case "confirm2":
                                    creatDiv(pageid,pageid+"_"+name,top,left,width,height,"√");
                                   break;
                               case "userDefinedInfo":
                                    CreateOrSubUserDefinedInfoDiv(pageid,pageid+"_"+name,top,left,width,height,text);
                                   break;
                               case "ORDER_GETADDRESS":
                                    if(ds.Tables[2].Rows[x].BYZD5=="1")
                                    {
                                        var address = ds.Tables[2].Rows[x].ServiceSiteProvince + ds.Tables[2].Rows[x].ServiceSiteCity + ds.Tables[2].Rows[x].ServiceSiteArea + ds.Tables[2].Rows[x].SS_Address + " 转( " + ds.Tables[2].Rows[x].ORDER_GETER + " " + ds.Tables[2].Rows[x].ORDER_GETERPHONE1 + " " + ds.Tables[2].Rows[x].ORDER_GETERPHONE2 + " )";
                                        creatDiv(pageid,pageid+"_"+name,top,left,width,height,address);
                                    }
                                    else
                                    {
                                        var address = ds.Tables[2].Rows[x].orderProvince + ds.Tables[2].Rows[x].orderCity + ds.Tables[2].Rows[x].orderArea + ds.Tables[2].Rows[x].ORDER_GETADDRESS;
                                        creatDiv(pageid,pageid+"_"+name,top,left,width,height,address);
                                    }
                                    break;
                               case "ORDER_GETER":
                                    if(ds.Tables[2].Rows[x].BYZD5=="1")
                                    {
                                        var geter = ds.Tables[2].Rows[x].ServiceSiteReceiver;
                                        creatDiv(pageid,pageid+"_"+name,top,left,width,height,geter);
                                    }
                                    else
                                    {
                                        creatDiv(pageid,pageid+"_"+name,top,left,width,height,eval("ds.Tables[2].Rows[x]."+name));
                                    }
                                    break;
                               case "ORDER_GETERPHONE1":
                                    if(ds.Tables[2].Rows[x].BYZD5=="1")
                                    {
                                        var phone = ds.Tables[2].Rows[x].Phone1;
                                        creatDiv(pageid,pageid+"_"+name,top,left,width,height,phone);
                                    }
                                    else
                                    {
                                        creatDiv(pageid,pageid+"_"+name,top,left,width,height,eval("ds.Tables[2].Rows[x]."+name));
                                    }
                                    break;
                               case "ORDER_GETERPHONE2":
                                    if(ds.Tables[2].Rows[x].BYZD5=="1")
                                    {
                                        var phone = ds.Tables[2].Rows[x].Phone2;
                                        creatDiv(pageid,pageid+"_"+name,top,left,width,height,phone);
                                    }
                                    else
                                    {
                                        creatDiv(pageid,pageid+"_"+name,top,left,width,height,eval("ds.Tables[2].Rows[x]."+name));
                                    }
                                    break;
                               default :
                                    //alert(name);
                                    //alert(eval("ds.Tables[2].Rows[x]."+name));
                                    var text=ds.Tables[1].Rows[j].text;
                                    creatDiv(pageid,pageid+"_"+name,top,left,width,height,eval("ds.Tables[2].Rows[x]."+name));
                                   break;
                            } 


                        }
                    }
                }
            }
        }
       }                
    return
}

function doPrint()
{
    
    if(typeof(jatoolsPrinter.page_div_prefix)=='undefined'){
        alert("请按页顶上的黄色提示下载ActiveX控件.如果没有提示请按以下步骤设置ie.\n 工具-> internet 选项->安全->自定义级别,设置 ‘下载未签名的 ActiveX ’为'启用'状态")
        return ;
    }
	//打印文档对象
//    var myreport ={ 
////    				print_settings:{
////    				pageWidth : 2270, 
////     				pageHeight : 800,
////     				orientation : 2
////							
////                                    },
//					documents: document,    // 打印页面(div)们在本文档中
////					marginIgnored:true,
//    				copyrights  :    '杰创软件拥有版权 www.jatools.com'         // 版权声明必须
//    			  };
    			  
    // 调用打印方法
    //if(how == '打印预览...')
//    	jatoolsPrinter.printPreview(myreport );   // 打印预览
                 
//   	else if(how == '打印...')
//   		jatoolsPrinter.print(myreport ,true);   // 打印前弹出打印设置对话框
//                
//   	else
//   		jatoolsPrinter.print(myreport ,false);       // 不弹出对话框打印


        var myreport = new Object();
        myreport.print_settings = new Object();
//        myreport.print_settings.printer="EPSON LQ-300K+II ESC/P2";
//        myreport.print_settings.pageWidth=3033;
//        myreport.print_settings.pageHeight=1707;
        myreport.print_settings.orientation=1;
        myreport.documents =document; // 打印页面div存在本页面中
        myreport.copyrights ="杰创软件拥有版权 www.jatools.com";

         //jatoolsPrinter.print(myreport ,true);
        jatoolsPrinter.printPreview(myreport );
}
    </script>

</head>
<body onload="Init()">
    <form id="form1" runat="server">
    <input id="hidExpressBillImagePath" type="hidden" runat="server" />
    </form>
</body>
</html>
